package com.java.study.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.study.entity.ChapterEntity;
import com.java.study.service.ChapterService;
import com.java.study.common.utils.PageUtils;
import com.java.study.common.utils.R;
/**
 * 
 *
 * @author jiangli
 * @email 31346337@qq.com
 * @date 2019-09-27 20:23:03
 */
@RestController
@RequestMapping("study/chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = chapterService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		ChapterEntity chapter = chapterService.getById(id);

        return R.ok().put("chapter", chapter);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ChapterEntity chapter){
		chapterService.save(chapter);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ChapterEntity chapter){
		chapterService.updateById(chapter);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		chapterService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
